package Singleton;

/**
 * 懒汉式单例模式
 */
public class SingletonExample2 {
    private static SingletonExample2 instance;

    private SingletonExample2() { // 私有构造方法，防止外部实例化
    }

    private synchronized static SingletonExample2 getInstance() { // 获取实例(线程安全)
        if (instance == null) {
            instance = new SingletonExample2();
        }
        return instance;
    }
}
